from pathlib import Path

from markitdown_api.app.handler.task_handler import TaskHandler, default_handler
from src.markitdown_api.app.models.task import Task
from markitdown_api.app.handler.markerpdf.marker_pdf_handler import MarkerPdfHandler


# 文件处理器工厂类
class _TaskHandlerFactory:

    def __init__(self):
        self._handlers = {
            # ".pdf": MarkerPdfHandler()
        }

    def get_handler(self, task: Task) -> TaskHandler:
        # 获取文件后缀
        file_extension = Path(task.input_path).suffix.lower()
        # 根据文件后缀获取对应的处理器，如果没有找到则使用默认处理器
        return self._handlers.get(file_extension, default_handler)


task_handler_factory = _TaskHandlerFactory()
